<?php 
header("Content-Type: text/html; charset=utf-8");
include_once 'public/DB_Oracle.php';
include_once 'public/page/page.class.php';
$DBsql = new DB_Oracle ();
if(isset($_GET['option'])){
if($_GET['option']=="del"){
	$sql="delete from paras_set_monitor dp where dp.MONITOR_ID in (".$_GET['id'].")";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('删除成功');window.location.href='listen.php';</script>";
	else
	echo "<script language='javascript'>alert('没有删除成功');window.location.href='listen.php';</script>";
	}
if($_GET['option']=="change"){
$sql="update paras_set_monitor dp
          set dp.vehicle_name='".$_GET['name']."',
		  dp.monitor_time=to_date('".$_GET['time']."', 'yyyy-mm-dd hh24:mi:ss'),
		  dp.use_state=".$_GET['is']."
		  where dp.monitor_id=".$_GET['n']."";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('修改成功');window.location.href='listen.php';</script>";
	else
	echo "<script language='javascript'>alert('没有修改成功');window.location.href='listen.php';</script>";
	}
if($_GET['option']=="add"){
$sql="insert into paras_set_monitor(monitor_id,vehicle_name,monitor_time,use_state)values(monito.nextval,'".$_GET['name']."',to_date('".$_GET['time']."', 'yyyy-mm-dd hh24:mi:ss'),".$_GET['is'].")";
if($DBsql->query($sql)){
	echo "<script language='javascript'>alert('添加成功');window.location.href='listen.php';</script>";
	}else{
	echo "<script language='javascript'>alert('没有添加成功');window.location.href='listen.php';</script>";}
}
	}
	
		$sql="select * from paras_set_monitor dp";
	$rows=$DBsql->fetch_all_array($sql);
$pageSize = 12;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
pageft($total, $pageSize, 1, 1, 1, 5);
$displaypg+=$firstcount;
$sql="select *
	  from (select rownum r,t.monitor_id,t.vehicle_name,to_char(t.monitor_time,'yyyy-mm-dd hh24:mi:ss') monitor_time,t.use_state from paras_set_monitor t) c
	 where c.r> $firstcount
	   and c.r<= $displaypg";
$rows=$DBsql->fetch_all_array($sql);
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script> 
<script language="javascript" type="text/javascript" src="js/date/WdatePicker.js"></script>
<script language="javascript">
function department(str){
	var url="cheliang.php?"+encodeURI("dep="+str);
	window.location=url;  
	}
function editRow(rowId){
	var obj=document.getElementById(rowId).getElementsByTagName('td');
		document.getElementById("charmoto_1").value=obj.item(0).innerHTML;
		document.getElementById("charmoto_2").value=obj.item(1).innerHTML;
		if(obj.item(2).innerHTML=='监听'){
			document.getElementById("charmoto_3").checked=true;
			}else{
				document.getElementById("charmoto_4").checked=true;
				}
				document.getElementById("charmoto_5").value=rowId;
				POPdiv('UPdiv');
	}
function CheckAll(obj){var chebox=document.getElementsByName('selectID');if(obj.checked==true){
for(var i=0;i<chebox.length;++i){chebox.item(i).checked=true;}}else{for(var i=0;i<chebox.length;++i){chebox.item(i).checked=false;}}
}
function delRow(policechar_id){
if(confirm("确定删除？")){
	var url="listen.php?"+encodeURI("option=del&id="+policechar_id);
	window.location=url; 
	}
	}
function select_value(obj){
	if(obj.value=='0'){
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_wrong Validform_checktip";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="没有输入";
	}
	else{obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_checktip Validform_right";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="输入正确";}
	
	}
function text_value(obj){
	if(obj.value==""){
		obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_wrong Validform_checktip";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="没有输入";		
		}else{obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_checktip Validform_right";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="输入正确";}
	}
function UP(){
if(document.getElementById("charmoto_1").value==""){
	alert("请检查你输入是否正确");
	return false;
	}if(document.getElementById("charmoto_2").value==""){
	 alert("请检查你输入是否正确");
			   return false;
			   }
var str_arr=[document.getElementById("charmoto_1").value,document.getElementById("charmoto_2").value];
if(document.getElementById("charmoto_3").checked==true){
	str_arr.push(1);
	}else{
	str_arr.push(0);	
		}str_arr.push(document.getElementById('charmoto_5').value);
	var url="listen.php?"+encodeURI("option=change&name="+str_arr[0]+"&time="+str_arr[1]+"&is="+str_arr[2]+"&n="+str_arr[3]);
	window.location=url;  
		}
function ADD(){
           if(document.getElementById("add_1").value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
		   if(document.getElementById("add_2").value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
var str_arr=[document.getElementById("add_1").value,document.getElementById("add_2").value];
	if(document.getElementById("add_3").checked==true){
		str_arr.push(1);
		}else{
		str_arr.push(0);
		}
	var url="listen.php?"+encodeURI("option=add&name="+str_arr[0]+"&time="+str_arr[1]+"&is="+str_arr[2]);
	window.location=url;  
		}
function groupSelect(){
	var policeID=$("#selectID").val();
	$('#departmentID').val(policeID);
	$('#Location').submit();
}
</script>
<!--管理列表开始-->
<div class="manageTab" style="margin-top:0px;">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv"><span><img src="images/001.gif" height="14" width="14" /><a href="javascript:void(null)" onclick="javascript:POPdiv('POPdiv')">新增</a></span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">定时参数</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td  class="td90b2">车辆</td>
            <td  class="td90b2">时间</td>
            <td  class="td90b2">状态</td>
            <td  class="td90b2">编辑</td>
            <td  class="td90b2">删除</td>
          </tr>
          <?php if(count($rows)!=0){
          		foreach ($rows as $ros){
          	?>
	          <tr id="<?php echo $ros['MONITOR_ID'];?>">
	            <td class="tdfff"><?php echo $ros['VEHICLE_NAME'];?></td>
                <td class="tdfff"><?php echo $ros['MONITOR_TIME'];?></td>
	            <td class="tdfff"><?php if($ros['USE_STATE']==1){echo "监听";}else{echo "没监听";}?></td>
	            <td class="tdfff"><div align="center"><img src="images/037.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="editRow('<?php echo $ros['MONITOR_ID'];?>')">编辑</a><span class="STYLE1">]</span></div></td>
	            <td class="tdfff"><div align="center"><img src="images/010.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="delRow('<?php echo $ros['MONITOR_ID'];?>')">删除</a><span class="STYLE1">]</span></div></td>
	          </tr>
          <?php }}else{echo '暂无数据！';}?>
          <tr>
            <td colspan="10" class="tdfff">&nbsp;</td>
          </tr>
        </table></td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
      <td height="24" width="8"><img src="images/user_03.gif" height="24" width="8" /></td>
      <td style="background:#3980b2;"><div class="green-black"><?php echo $pagenav;?>
        </div></td>
      <td height="24" width="8"><img src="images/user_04.gif" height="24" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->
      
<!--弹出层开始-->
<div id="POPdiv" class="POPdiv">
  <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('POPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>车辆管理</div>
  <div class="POPdiv_content">
    <form action="" method="post">
     <table border="0" cellpadding="5" cellspacing="0">
                <tr>
			      <td width="80"><label for="userNameUp">车辆：</label></td>
			      <td><input type="text" id="add_1" onblur="text_value(this)"/></td>
			      <td><span class="Validform_checktip">请输入车辆名字</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userNameUp">时间：</label></td>
			      <td><input type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width:140px"  id="add_2" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">请输入时间</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userSimUp">选择初始状态</label></td>
			      <td><input id="add_3" checked="checked" type="radio" name="radio_xy"/>启用<input id='add_4' type="radio" name="radio_xy"  value="0"/>禁用</td>
			      <td><span class="Validform_checktip">请选择</span></td>
			    </tr>
                <tr>
			      <td colspan="3"><input id="up" type="button" class="btnbg" onclick="ADD()" value="添加监控信息" style="width:100px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
    </form>
  </div>
</div>
<!--弹出层结束-->
<!--弹出层修改车辆数据开始-->
      <div id="UPdiv" class="POPdiv">
        <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('UPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>修改警员信息</div>
        <div class="POPdiv_content">
          <form class="adduser" id="upuser" action="" method="post">
			  <table border="0" cellpadding="5" cellspacing="0">
                <tr>
			      <td width="80"><label for="userNameUp">车辆：</label></td>
			      <td><input type="text" id="charmoto_1" onblur="text_value(this)"/></td>
			      <td><span class="Validform_checktip">请输入车辆名字</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userNameUp">时间：</label></td>
			      <td><input type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width:140px"  id="charmoto_2" onblur="text_value(this)" /></td>
			      <td><span class="Validform_checktip">请输入时间</span></td>
			    </tr>
                <tr>
			      <td width="80"><label for="userSimUp">选择初始状态</label></td>
			      <td><input id="charmoto_3" checked="checked" type="radio" name="radio_xy"/>启用<input id='charmoto_4' type="radio" name="radio_xy"  value="0"/>禁用</td>
			      <td><span class="Validform_checktip">请选择</span></td>
			    </tr>
                <tr>
			      <td colspan="3"><input type="hidden" id="charmoto_5" name="departmentID" value=""><input id="up" type="button" class="btnbg" onclick="UP()" value="更新监控信息" style="width:100px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
		  </form>
        </div>
      </div>
<!--弹出层修改车辆数据层结束-->